// pages/order/order.js
Page({
  data: {
    diagnose: {},
    user: {},
    isFromDiagnose: false,
    addInfo:'',
  },
  onLoad: function (options) {
    this.setData({
      user: wx.getStorageSync('user')
    })
    console.log(this.data.user)
    console.log('options', options)
    var that = this
    console.log('flowId', options.flowId)
    console.log('isFromDiagnose', options.isFromDiagnose)
    //看看是否从就诊来的
    if (options.isFromDiagnose) {
      that.setData({
        isFromDiagnose: options.isFromDiagnose
      })
    }
    //获取就诊信息
    wx.cloud.callFunction({
      name: 'diagnose',
      data: {
        action: 'findOneByFlowId',
        flowId: options.flowId,
        // flowId:"321700229102220210428004",
      }
    }).then(res => {
      console.log('寻找这条就诊信息成功', res.result.data[0])
      that.setData({
        diagnose: res.result.data[0]
      })
    }).catch(res => {
      console.log('寻找这条就诊信息失败', res)
    })
  },
  //获取追加信息
  getaddInfo(e) {
    this.setData({
      addInfo:e.detail.value
    })
  },
  //提交追加信息
  commit() {
    var that=this
    wx.cloud.callFunction({
      name:'diagnose',
      data:{
        action:'changeAddInfoByFlowId',
        flowId:that.data.diagnose.flowId,
        addInfo:that.data.addInfo
      }
    }).then(res=>{
      console.log('修改追加信息成功',res)
      wx.showToast({
        title: '追加信息成功',
      })
    }).catch(res=>{
      console.log('修改追加信息失败',res)
    })
  },
  //返回到预约列表
  goAppoint() {
    wx.navigateTo({
      url: '/pages/appointHistoryB/appointHistoryB?doctorId='+this.data.diagnose.appoint.doctorId,
    })
  }
})